<?php
namespace admin;
use models\BaseDao;
class Payway extends Admin{
    public function  __construct(){
        parent::__construct();
        $this->assign('menumark','payway');
    }
/**
 * 支付方式列表页面
 */
    function index(){
        // 获取数据库操作对象
        $db = new BaseDao();
        // 获取全部支付方式,按照ord排序
        $data = $db->select('payway','*',['ORDER'=>['ord'=>'ASC','id'=>'ASC']]);
        // 将数据全部分给模板
        $this->assign('data',$data);

        //标题    
        $this->assign('title','支付方式');
        // 导入模板
        $this->display('payway/index');
    }

    function mod($id){
        $db = new BaseDao();
        $this->assign($db->get('payway','*',['id'=>$id]));

        $this->assign('qt',['1'=>'启用','0'=>'停用']);
        $this->assign('title',"修改支付方式");
        $this->display('payway/mod');
    }


    function doupdate(){
        $id = $_POST['id'];
        unset($_POST['id']);
        $db = new BaseDao();
        if($db->update('payway',$_POST,['id'=>$id])){
            $this->success('/admin/payway','修改ok');
        }else{
            $this->error('/admin/payway/mod/'.$id,'修改fail');
        }
    }

    function order(){
        $db = new BaseDao();
        $num = 0;
        foreach($_POST['ord'] as $id=>$ord){
            
            $num += $db->update('payway',['ord'=>$ord],['id'=>$id]);
        }
        if($num > 0){
            $this->success('/admin/payway','排序ok');
        }else{
            $this->success('/admin/payway','排序fail');
        }
    }
}